clear
use car_sa1.dta

gen dmpi3 = l_mdmh1*l_persindex

xtset country1 year



***ZINB baseline - Figure 3
clear
use car_sa1.dta
gen dmpi3 = l_mdmh1*l_persindex

zinb aid l_mdmh1 l_persindex dmpi3 ///
	l_incentives l_enop1 l_vprange  ///
	econenop econpolicyvp  ///
	i.country1 i.year, ///
	inflate(l_mdmh1 l_persindex dmpi3 ///
	l_incentives l_enop1 l_vprange  ///
	econenop econpolicyvp) r difficult 
estimates store zinb_base1a

gen yline = 0

matrix b=e(b) 
matrix V=e(V)
 
scalar b1=b[1,1]
scalar b8=b[1,2]
scalar b9=b[1,3]

scalar varb1=V[1,1]
scalar varb8=V[2,2]  
scalar varb9=V[3,3]

scalar covb1b9=V[1,3] 
scalar covb8b9=V[2,3]

scalar list b1 b8 b9 varb1 varb9 varb8 covb1b9 covb8b9


generate MVZ2=((_n)/10)
replace  MVZ2=. if _n>1500

gen conbx2=b1+b9*MVZ2 if _n<1501
gen conbxse2=sqrt(varb1+varb9*(MVZ2^2)+2*covb1b9*MVZ2) if _n<1501
gen ax2=1.65*conbxse2
gen upperx2=conbx2+ax2 
gen lowerx2=conbx2-ax2


graph twoway hist l_mdmh1 if l_mdmh1 < 25, width(1) percent color(gs14) yaxis(2) ///
		||	 line conbx2   MVZ2 if MVZ2 < 25, clwidth(0.3) clcolor(black) clpattern(solid)  ///
        ||   line upperx2  MVZ2 if MVZ2 < 25, clpattern(dash) clwidth(thin) clcolor(black) ///
        ||   line lowerx2  MVZ2 if MVZ2 < 25, clpattern(dash) clwidth(thin) clcolor(black) ///
		||   line yline  MVZ2 if MVZ2 < 25,  clwidth(thin) clcolor(black) clpattern(solid) ||, ///
             xscale(noline) xlabel(, nogrid labsize(2.5)) ///
             ylabel(, axis(1) nogrid labsize(2.5)) ///
			 ylabel(, axis(2) nogrid labsize(2.5)) ///
             yscale(noline alt) ///
			 yscale(noline alt  axis(2)) ///
			 legend(off) ///
             xtitle("{it:District Magnitude}", size(2.5)) ///
			 ytitle("Percentage", axis(2) size(2.5)) ///
             xsca(titlegap(2)) ///
             ysca(titlegap(2)) ///
             ytitle("Marginal Effect of {it:Personal Vote}", axis(1) size(2.5)) ///
             scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white)) ///
			 saving(dmxpi3, replace)
			 
			 
generate MVX2=((_n-1)/100)
replace  MVX2=. if _n>167

gen conbz2=b8+b9*MVX2 if _n<168
gen conbzse2=sqrt(varb8+varb9*(MVX2^2)+2*covb8b9*MVX2) if _n<168
gen az2=1.65*conbzse2 
gen upperz2=conbz2+az2 
gen lowerz2=conbz2-az2

graph twoway hist l_persindex, width(0.1) percent color(gs14) yaxis(2) ///
		||	 line conbz2   MVX2, clwidth(0.3) clcolor(black) clpattern(solid)  ///
        ||   line upperz2  MVX2, clpattern(dash) clwidth(thin) clcolor(black) ///
        ||   line lowerz2  MVX2, clpattern(dash) clwidth(thin) clcolor(black) ///
		||   line yline  MVX2,  clwidth(thin) clcolor(black) clpattern(solid) ||, ///
             xlabel(, nogrid labsize(2.5)) /// 
			 xscale(noline) ///
             ylabel(,  axis(1) nogrid  labsize(2.5)) ///
			 ylabel(, axis(2) nogrid labsize(2.5)) ///
             yscale(noline alt) ///
			 yscale(noline alt axis(2)) ///
			 legend(off) ///
             xtitle("{it:Personal Vote}", size(2.5)) ///
			 ytitle("Percentage", axis(2) size(2.5)) ///
             xsca(titlegap(2)) ///
             ysca(titlegap(2)) ///
             ytitle("Marginal Effect of {it:District Magnitude}", axis(1) size(2.5)) ///
             scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white)) ///
			 saving(pixdm3, replace)



***combine graphs
graph combine dmxpi3.gph pixdm3.gph, ycommon col(2) graphregion(fcolor(white)) saving(zinb_marg_eff, replace)


